﻿@model LeadMaster.ViewModels.ViewModelOutsourcer

<style type="text/css">
.InfoRowHeight
{
    height: 20px;   
}
.sectionheader
{
    font-size: 9px;
    text-align: left;
 }
</style>


@{
    ViewBag.Title = "Show Leads";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="spacer"></div>

<table>
<tr class="InfoRowHeight">
<td rowspan="6"><img src="~/Images/Dunsmore.png" style="width: 120px; height: 120px" /></td>
<td colspan="3">&nbsp;</td>
</tr>
<tr class="InfoRowHeight">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="InfoRowHeight">
<td><label>Client</label></td>
<td><label style="font-weight:bold; color: #000000;">@Model.Leads.IntRef.Trim()</label></td>
<td><label>CONFIDENTIALITY NOTICE</label></td>
</tr>
<tr class="InfoRowHeight">
<td><label>Total Leads</label></td>
<td><label style="font-weight:bold; color: #000000;">
@ViewBag.TotalLeads
</label></td>
<td><label>This Lead information is Confidential, Exclusive and for the intended addressee only under Non-Disclosure Agreement and may be legally privileged and protected by law.</label></td>
</tr>
<tr>
<td><label>Return Date</label></td>
<td>
<label style="font-weight:bold; color: #000000;">
@ViewBag.ReturnDate
</label>
</td>
<td><label>as soon as possilbe. Legal professional privilege may apply and is not waived for  unintended recipients.</label></td>
</tr>
<tr class="InfoRowHeight">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</table>
@if (@Model.FullListLeadResults != null && @Model.FullListLeadResults.Count() > 0)
{
<div class="spacer"></div>
<table style="width:3500px;">
<tr>
@for (int i = 0; i < @Model.Titles.Count(); i++)
{
    <th>
    <label style="color: #FF0000; font-size: 9px; font-family: Arial, Helvetica, sans-serif; font-weight: bold;">
    @if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.ClientNote!=null)
        {
            @Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.ClientNote
        }
    }
    </label>
    </th>    
}
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>

</tr>

<tr>
@{
int colSpan = 1;
string blockTitle = "";
string bgColour = ""; 
for (int i = 0; i < @Model.Titles.Count(); i++)
{
    if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID != null && Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID > 0)
    {
        if (blockTitle == Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.LeadStat.Title)
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" style="text-align: left; background-color: #@(bgColour);"><label class="sectionheader">@blockTitle</label></th>                    
            }
			blockTitle = Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.LeadStat.Title;
			bgColour = Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.LeadStat.BackgroundColour;
            colSpan = 1;
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (blockTitle == Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.LeadGroups.Title)
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" style="text-align: left; background-color: #@(bgColour);"><label class="sectionheader">@blockTitle</label></th>                
            }
			blockTitle = Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.LeadGroups.Title;
			bgColour=Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.LeadGroups.BackgroundColour;
            colSpan = 1;
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID != null && Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID > 0)
    {
        if (blockTitle == "Registration")
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" style="text-align: left; background-color: #@(bgColour);"><label class="sectionheader">@blockTitle</label></th>
            }
            colSpan = 1;
            blockTitle = "Registration";
			bgColour="BFFFFF";
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID != null && Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID > 0)
    {
        if (blockTitle == "Restriction")
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
            <th colspan="@(colSpan)" style="text-align: left; background-color: #@(bgColour);"><label class="sectionheader">@blockTitle</label></th>
            }
            colSpan = 1;
            blockTitle = "Restriction";
			bgColour="BFFFFF";
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.CompanySundriesID != null && Model.FullListLeadResults[i].LeadResult.CompanySundriesID > 0)
    {
        if (blockTitle == "Sundries")
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
            <th colspan="@(colSpan)" style="text-align: left; background-color: #@(bgColour);"><label class="sectionheader">@blockTitle</label></th>
            }
            colSpan = 1;
            blockTitle = "Sundries";
			bgColour="BFFFFF";
        }
    }
} 
<th colspan="@(colSpan)" class="topsectiontitles"><label class="sectionheader">@blockTitle</label></th>
}
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<tr>
@for (int i = 0; i < @Model.Titles.Count(); i++)
{
    <th style="background-color: #BFFFFF;">
    <label style="color: #FF0000;">
    @if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID != null && Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.Mandatory == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    @if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.Mandatory == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    @if (Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID != null && Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.CompanyRegistered.MandatoryLeadQuestion == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    @if (Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID != null && Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.CompanyRestriction.MandatoryLeadQuestion == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }    
    @if (Model.FullListLeadResults[i].LeadResult.CompanySundriesID != null && Model.FullListLeadResults[i].LeadResult.CompanySundriesID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.CompanySundry.MandatoryLeadQuestion == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }    
    </label>
    </th>    
}
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<tr>
@for (int i = 0; i < @Model.Titles.Count(); i++)
{
    <th style="border: 1px solid #000000; background-color: #999999;">
    <label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
    @Model.Titles[i]
    </label>
    </th>    
}
<th style="border: 1px solid #000000; background-color: #999999;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Purchase Order
</label>
</th>
<th style="border: 1px solid #000000; background-color: #999999;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
New or Replacement  
</label>
</th>
<th style="border: 1px solid #000000; background-color: #999999;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Current Status
</label>
</th>
<th style="border: 1px solid #000000; background-color: #999999;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Return Reason
</label>
</th>
<th style="border: 1px solid #000000; background-color: #999999; width: 100px;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Your Notes
</label>
</th>

</tr>
<tr>
@{
int iCounter = 0;
foreach (var item in Model.FullListLeadResults)
{
    <td style="border: 1px solid #000000;">
    <label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;">
    @item.LeadResult.Answer
    </label>
    </td>
    iCounter++;
    if (iCounter == item.LeadResult.QuestionBlock)
    {
        <text>
            <td style="border: 1px solid #000000;">
            <label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; cursor: pointer;" class="changeleadreason" data-id="@(item.LeadResult.LeadResultsID)">
            @if (item.LeadStatus.PurchaseOrder!=null)
            {
                @item.LeadStatus.PurchaseOrder.PID
            }
            else
            {
             @:&nbsp;   
            }
            </label>
            </td>
            <td style="border: 1px solid #000000;">
            <label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; cursor: pointer;" class="changeleadreason" data-id="@(item.LeadResult.LeadResultsID)">
            @if(item.LeadStatus.Replacement!=null)
            {
                @item.LeadStatus.Replacement.ToString().Replace("True","Replacement")
            }
            else
            {
                @:New
            }
            </label>
            </td>
            <td style="border: 1px solid #000000;">
            @if (item.LeadFlag.LeadFlagsID==1)
            {
                <input type="button" value="Release To Client" class="btnReleaseToClient" data-id="@(item.LeadStatus.LeadStatusID)"/>
            }
            else
            {
                <label style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; " data-id="@(item.LeadResult.LeadResultsID)">
                    @item.LeadFlag.Description
                </label>
            }
            </td>
            <td style="border: 1px solid #000000;">
            <label style="font-family: Arial, Helvetica, sans-serif; font-size: 11px;" data-id="@(item.LeadResult.LeadResultsID)">
                @item.LeadReason.Description @item.LeadStatus.Notes @item.QCReason @item.LeadStatus.QCManfield
            </label>
            </td>
            <td style="border: 1px solid #000000;">
            <label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; cursor: pointer;" class="changeosnotes" data-id="@(item.LeadStatus.LeadStatusID)">
            @if (item.LeadStatus.OutsourcerNotes==null)
            {
                @:Enter a note
            }
            else
            {
                @item.LeadStatus.OutsourcerNotes; 
            }
            </label>
            </td>
            <td>
            @if(item.LeadFlag.LeadFlagsID==1)
            {
                @:<input type="button" value="Edit" class="EditLead" data-leadid="@(item.LeadResult.LeadID)" data-blockid="@(item.LeadResult.BlockId)" />
            }
            else if(item.LeadFlag.LeadFlagsID==5)
            {
                @:<input type="button" value="Refresh" class="EditLead" data-leadid="@(item.LeadResult.LeadID)" data-blockid="@(item.LeadResult.BlockId)" />
            }
            else
            {
                @:&nbsp;
            }
            </td>
        </text>
        @:</tr><tr>
        iCounter = 0;
    }
}
}
</tr>
</table>
}
else
{
<h3>No Leads.</h3>
}
<div id="changestatus"></div>
<div id="changereason"></div>
<div id="osnote"></div>
<input type="hidden" id="refreshmessage" value="false" />

<script type="text/javascript">
    $(document).ready(function () {

        $("#changestatus").dialog(
        {
            autoOpen: false,
            width: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                save: function () {
                    $(this).dialog("close");
                    $("#formChangeLeadStatus").submit();
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        $("#changereason").dialog(
        {
            autoOpen: false,
            width: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                save: function () {
                    $(this).dialog("close");
                    $("#formChangeReason").submit();
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        $("#osnote").dialog(
        {
            autoOpen: false,
            width: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                save: function () {
                    $(this).dialog("close");
                    $("#formOsNote").submit();
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });
        $(".changeleadstatus").click(function () {
            $("#changestatus").dialog("open");
            $('#changestatus').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadStatus", "Outsourcer"))/?id=' + $(this).data("id");
            $('#changestatus').load(contactURL);
        });

        $(".changeleadreason").click(function () {
            $("#changereason").dialog("open");
            $('#changereason').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadReason", "Outsourcer"))/?id=' + $(this).data("id");
            $('#changereason').load(contactURL);
        });

        $(".changeosnotes").click(function () {
            $("#osnote").dialog("open");
            $('#osnote').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeOsNote", "Outsourcer"))/?id=' + $(this).data("id");
            $('#osnote').load(contactURL);
        });

        $(".btnReleaseToClient").click(function () {
            var contactURL = '@(Url.Action("ReleaseToClient", "Outsourcer"))/?id=' + $(this).data("id");
            window.location.href = contactURL;
        });

        $(".EditLead").click(function () {
            if ($("#refreshmessage").val() == "false") {
                alert("If you are Refreshing this lead, please enter details into Your Notes what you have done to revive the lead. Dunsmore QC will read your notes to be aware of what actions you have done.");
            }
            $("#refreshmessage").val("true");
            var contactURL = '@(Url.Action("EditLeads", "Outsourcer"))?leadID=' + $(this).data("leadid") + '&blockID=' + $(this).data("blockid");
            window.location.href = contactURL;
        });
    });
</script>
